package RTL.Task5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;


public class pokerGame {

    public static void main(String[] args) {

        //创建map集合
        List list = new ArrayList();
        HashMap<Integer,String> map = new HashMap<Integer,String>();
        //创建所有牌
        String[] color = {"♥","♦","♠","♣"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        int num = 0;
        for(int i = 0 ;i< number.length;i++){
            for(int j = 0 ;j< color.length;j++){
                map.put(num,color[j]+number[i]);
                list.add(num);
                num++;
            }
        }

        list.add(list.size());
        list.add(list.size());
        map.put(list.size()-2,"Big Joker");
        map.put(list.size()-1,"Small Joker");

        //将序号集合打乱
        Collections.shuffle(list);

        //创建三名玩家和底牌
        List player1 = new ArrayList();
        List player2 = new ArrayList();
        List player3 = new ArrayList();
        List cards = new ArrayList();
        //循环分发序号（发牌）
        for(int i = 0 ;i<list.size();i++){
            if(i<list.size()-3){
                if(i % 3 == 1){
                    player1.add(list.get(i));
                }else if(i % 3 == 2){
                    player2.add(list.get(i));
                }else{
                    player3.add(list.get(i));
                }
            }else{
                cards.add(list.get(i));
            }
        }
        //将分的牌进行排列
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(player3);
        Collections.sort(cards);
        //遍历将3个玩家和底牌分得的序号集合
        pokerCollections(map, player1);
        pokerCollections(map, player2);
        pokerCollections(map, player3);
        pokerCollections(map, cards);

        //4.看牌
        //打印输出三名玩家的牌的底牌
        System.out.println(player1);
        System.out.println(player2);
        System.out.println(player3);
        System.out.println(cards);
    }

    private static void pokerCollections(HashMap<Integer, String> map,List list) {
        for(int i = 0;i < list.size();i++){
            list.set(i, map.get(list.get(i)));
        }
    }
}